import React,{Component} from "react";
import { Form, Button, Input, Table, Pagination,Select, Row, Col, DatePicker, message } from "antd";

class Flight extends Component{
    constructor(props){
        super(props);
        this.state = {
            UIstate:{
                nomalDisplay:"block",
                addDispaly:"none",
            },
            data:{}
        }
    }
    addItem = (e) =>{
        this.setState({UIstate:{nomalDisplay:"none", addDispaly:"block"}});
        this.props.form.resetFields();
        //设置清空里面的内容
    }
    backClick = (e) =>{
        this.setState({UIstate:{nomalDisplay:"block", addDispaly:"none"}});
    }
    companyChange = (e) =>{
        //每次改变就查询对应公司下的数据吧
        console.log("companyChange");
    }
    onSubmit = (e) =>{}
    onSearch = (e) =>{}
    
    render(){
        console.log("state-flight", this.state);
        const state = this.state;
        const { getFieldProps } = this.props.form;
        const _this = this;
        const rowSelection = {
            onChange(selectedRowKeys, selectedRows) {
              _this.setState({selectedRows});
            }
        };
        const columns = [
            {
                title: '所属公司',
                dataIndex: 'companyName',
                key: 'companyName',
                width:200,
                render: (text) => <span href="#">{text}</span>,
            },{
                title: '起飞地点',
                dataIndex: 'startAirport',
                key: 'startAirport',
                width:200,
            },{
                title: '起飞时间',
                dataIndex: 'startTime',
                key: 'startTime',
                width:200,
            },{
                title: '飞机型号',
                dataIndex: 'airplane',
                key: 'airplane',
                width: 150,
            },{
                title: '餐饮',
                dataIndex: 'food',
                key: 'food',
                width: 100,
                render: (text, record) => (<span>{(()=>{
                    let res = "无";
                    switch(text){
                        case "1":res = "正餐";break;
                        case "2":res = "小食";break;
                        case "3":res = "饮料";break;
                    }
                    return res;
                })()}</span>),
            }, {
                title: '操作',
                key: 'operation',
                fixed: 'right',
                width:100,
                render: (text, record) => (
                <span>
                    <a href="#">详情{record.name}</a>
                    <span>|</span>
                    <a href="#">删除{record.name}</a>
                </span>
                ),
            }
        ];
        let data = [], n = 20;
        for(let i = 0; i < n; i++){
            data.push({
                key:""+i,
                companyName:"公司名称"+i,
                startAirport:"起飞地点"+i,
                startTime:"2019-4-20 12:32",
                airplane:"中型机"+i,
                food:0,
            });
        }
        return(
        <div className="flight">
            <div className="nomal" style={{display: state.UIstate.nomalDisplay}}>
                <div className="contral">
                    <Form layout="inline" onSubmit={this.onSearch}>
                        <Form.Item>
                            <Button onClick={this.addItem}>新增</Button>
                        </Form.Item>
                        <Form.Item>
                            <Button>删除选中</Button>
                        </Form.Item>
                        <Form.Item label="公司名称">
                            <Input placeholder="公司名称" {...getFieldProps('fCompany')}></Input>
                        </Form.Item>
                        <Form.Item>
                            <Button className="search">查询</Button>
                        </Form.Item>
                    </Form>
                </div>
                <Table className="c-table table"
                    rowSelection={rowSelection} 
                    columns={columns} dataSource={data} 
                    scroll={{ y: 400}}
                    // onChange={this.tableChange}
                    pagenation={
                        <Pagination
                            total={80}
                            showTotal={total => `共 ${total} 条`}
                            pageSize={20} defaultCurrent={1}
                        />
                    }
                ></Table>
            </div>
            <div className="add" style={{display: state.UIstate.addDispaly}}>
                <div className="contral">
                    {/* <Button className="save" onClick={this.saveClick}>保存</Button> */}
                    <Button className="back" onClick={this.backClick}>返回</Button>
                </div>
                <Form onSubmit={this.onSubmit}>
                </Form>
            </div>
        </div>)
    }
}

export default Form.create({})(Flight);